<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars 
define("PRIMARY_KEY","debtur_id");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_setup_debtur.php";
$FileTemplate  = "ais_setup_debtur_list.html";
$SubHeaderTitle = "Debitur";
$PageSize      = 10 ;
$HTMLGridList  = "StaffGrid";
$TableName = "tbldebtur";
//************ FORM ACTION **************
	if (GetParam("Action","")=="Delete") {
		DeleteRecord ("txtCheck",$PageSize);
	}

//Initiate Database Table For Search;
$FCode = GetParam("CodeSearch","");
$FNama = GetParam("CustSearch","");
$QueryGet  = GetQueryString("All", array('PageNum'));

//******* DATABASE FORM QUERY ***********
$SQL = "Select * from $TableName ";
//$SQLCount = "SELECT count(*) FROM $TableName ";

if ($FNama) 
	if (strlen($WHERE)) $WHERE .= " AND "." CUNAME like '%".$FNama."%'";
	else $WHERE .= " CUNAME like '%".$FNama."%'";	
if ($FCode) 
	if (strlen($WHERE)) $WHERE .= " AND "." CUDEBTUR like '%".$FCode."%'";
	else $WHERE .= " CUDEBTUR like '%".$FCode."%'";

	
	if (strlen($WHERE))	$WHERE = " WHERE ".$WHERE;
	//else $WHERE = " WHERE 1";

$SQL = $SQL.$WHERE." ORDER BY debtur_id DESC";
//$SQLCount = $SQLCount.$WHERE." ORDER BY CUNAME";


//******* SHOW FORM CONTENT *********
//Default value
if (!isset($_GET)) $_GET=&$HTTP_GET_VARS ;
if (isset($_GET['PageNum'])) {
  $PageNum = $_GET['PageNum'] ;
} else {
    $PageNum = 1 ;
}

//Default value
if (isset($_GET['RecCnt'])) {
  $RecCnt = intval($_GET['RecCnt']) ;
} else {
    $RecCnt = -1 ;
} 

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$RecCnt = $TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ; 
$TBS->Show();


function DeleteRecord ($sequence_name,$PageSize) {
	global $DBConnection,$FileName,$TableName;
        if (GetParam("PageNum","")) {
          $StartRecord = GetParam("PageNum","")*$PageSize-$PageSize+1;
          $EndRecord   = $StartRecord+$PageSize-1;
          
        } 
	for ($x=$StartRecord;$x<=$EndRecord;$x++) {
		if (GetParam($sequence_name.$x,""))	{
			$DBConnection->Delete("$TableName",$sequence_name.$x);
	    }
	}
	header("Location: $FileName");
	exit;	
	
}

?>
